package com.atguigu.Controller;

import com.atguigu.Serivce.CategoryService;
import com.atguigu.Utils.R;
import com.atguigu.pojo.Category;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping("page")
    public R page(Integer page, Integer pageSize) {

        return categoryService.page(page,pageSize);
    }

    @PostMapping
    public R add( @RequestBody Category category) {
        return categoryService.add(category);
    }

    @PutMapping
    public R updateCategory(@RequestBody Category category) {
        return categoryService.updateCategory(category);
    }

    @DeleteMapping
    public R deleteCategory(Long ids) {
        return categoryService.deleteCategory(ids);
    }

    @GetMapping("list")
    public R list(Category category) {
        return categoryService.listType(category.getType());
    }
}
